<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Provinsi extends CI_Controller {
	
	function __construct() {
    parent::__construct();	
		$this->isLogin();	
		$this->load->model('provinsi_model');
	}
	
	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}

	public function index(){
		$data['main_view']='admin/provinsi/read';
		$data['hasil']=$this->provinsi_model->read();
		$this->load->view('admin/template',$data);
	}
	
	function add(){
		$data['main_view']='admin/provinsi/add';
		$this->load->view('admin/template',$data);
	}
	
	function proses_add(){
		$data = array(
			'provinsi' => $this->input->post('provinsi')
		);

		if($query=$this->provinsi_model->add($data)){
			$this->session->set_flashdata('pesan', 'Data Sukses Ditambah');
			redirect('provinsi');
		}
	}
	
	function edit($id){
		$data['main_view']='admin/provinsi/edit';
		$data['hasil']=$this->provinsi_model->edit($id);
		$this->load->view('admin/template',$data);
	}
	
	function proses_update(){
		$id = $this->input->post('id_provinsi');
		$data = array(
			'provinsi' => $this->input->post('provinsi')
		);

		if($query=$this->provinsi_model->update($id,$data)){
			$this->session->set_flashdata('pesan', 'Data Sukses Ditambah');
			redirect('provinsi');
		}
	}
	
	function delete($id){
		$this->provinsi_model->delete($id);
		$this->session->set_flashdata('pesan', 'Data Sukses Dihapus');
		redirect('provinsi');
	}
}